package az.mecid.rssreader.client.view;

import az.mecid.rssreader.client.model.FeedItem;
import az.mecid.rssreader.client.presenter.ReaderPresenter;
import az.mecid.rssreader.client.ui.widget.FeedItemWidget;
import az.mecid.rssreader.client.ui.widget.NavigationWidget;
import az.mecid.rssreader.client.ui.widget.ReaderWidget;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.logical.shared.HasSelectionHandlers;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: mega
 * Date: 24.02.2010
 * Time: 17:00:26
 */
public class ReaderView extends Composite implements ReaderPresenter.Display{

    interface Binder extends UiBinder<Widget,ReaderView>{}
    public static Binder binder = GWT.create(Binder.class);

    @UiField
    NavigationWidget navigationWidget;

    @UiField
    ReaderWidget readerWidget;

    public ReaderView(){
        initWidget(binder.createAndBindUi(this));
    }

    public HasClickHandlers getAddButton() {
        return navigationWidget.getFeedAddWidget().getAddFeedButton();
    }

    public HasSelectionHandlers getMenu() {
        return navigationWidget.getMenuWidget().getMenu();
    }

    public HasValue<String> getAddedFeed() {
        return navigationWidget.getFeedAddWidget().getFeed();
    }

    public void setData(List<FeedItem> items) {
        HasWidgets content = readerWidget.getContent();
        content.clear();

        for(FeedItem item : items)
            content.add(new FeedItemWidget(item.getUrl(),item.getTitle(),item.getDescription()));
    }

    public Widget asWidget() {
        return  this;
    }
}